package com.marion.study.aop.pattern.dynamicproxy;

import com.marion.study.aop.pattern.staticproxy.RealImage;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * JDK动态代理
 */
public class JdkDynamicProxy implements InvocationHandler {

    private RealImage realImage;

    public JdkDynamicProxy(RealImage image) {
        this.realImage = image;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) {

        System.out.println("[invoke] start...");

        Object result = null;

        try {
            result = method.invoke(realImage, args);
        } catch (Exception e) {
            System.out.println("[invoke] error..." + e.getMessage());
        }

        return result;

    }
}
